package com.example.appforphysician;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.appforphysician.adapter.ServiceConnector;

public class MainActivity extends Activity {
	private Button buttonLogin, buttonRegistry;
	private TextView edtUser, edtPass, edtLoginResult;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initializeComponents();
	}

	private void initializeComponents() {
		// To change body of created methods use File | Settings | File
		// Templates.
		buttonLogin = (Button) findViewById(R.id.btnLogin);
		buttonRegistry = (Button) findViewById(R.id.btnRegistry);

		edtUser = (TextView) findViewById(R.id.edtUser);
		edtPass = (TextView) findViewById(R.id.edtPass);
		edtLoginResult = (TextView) findViewById(R.id.edtLoginResult);

		buttonLogin.setOnClickListener(buttonLoginClickListener);
		buttonRegistry.setOnClickListener(buttonRegistryClickListener);
	}

	private View.OnClickListener buttonLoginClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			// send informantion to Server
			// -----------------Login--------------------
			String username = edtUser.getText().toString();
			String password = edtPass.getText().toString();
			if (ServiceConnector.getSingleton().doLogin(username, password)) {
				// -----------------Change Screen-------------
				Intent intent = new Intent(getApplicationContext(),
						ManagerActivity.class);
				startActivity(intent);
			} else {
				edtLoginResult.setText("Wrong username or password");
				edtUser.setText("");
				edtPass.setText("");
			}
		}
	};
	private View.OnClickListener buttonRegistryClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			
		}
	};

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	
	
	
	
	
}
